package org.example.JVM.Proxy.JDK;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

/**
 * @description:
 * @author: farprt
 * @create: 2022-12-06 20:35
 **/
public class HttpRequestInvocationHandler implements InvocationHandler {

    private HttpRequestTemplate target;

    public HttpRequestInvocationHandler(HttpRequestTemplate target) {
        this.target = target;
    }


    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        long startMs = System.currentTimeMillis();
        try {
            return method.invoke(target, args);
        } finally {
            long cntMs = System.currentTimeMillis() - startMs;
            System.out.println(method.getName() + "方法执行时间为" + cntMs + "ms");
        }
    }
}